import Vue from 'vue'
import VueRouter from 'vue-router'
import { AuthLayout, TabLayout, BasicLayout } from '@/layouts'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: TabLayout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home')
      },
      {
        path: 'chance',
        name: 'chance',
        component: () => import('@/views/chance')
      },
      {
        path: 'talk',
        name: 'talk',
        component: () => import('@/views/talk')
      },
      {
        path: 'mine',
        name: 'mine',
        component: () => import('@/views/mine'),
        meta: {
          title: '个人中心',
          navbar: {
            style: { backgroundColor: 'rgba(0, 0, 0, 0)', color: '#ffffff' }
          }
        }
      }
    ]
  },

  {
    path: '/auth',
    component: AuthLayout,
    redirect: '/auth/login',
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import('@/views/auth/login'),
        meta: { title: '手机号登录' }
      },
      {
        path: 'register',
        name: 'register',
        component: () => import('@/views/auth/register'),
        meta: { title: '手机号注册' }
      },
      {
        path: 'forget',
        name: 'forget',
        component: () => import('@/views/auth/forget'),
        meta: { title: '忘记密码' }
      }
    ]
  },

  {
    path: '/product',
    component: BasicLayout,
    children: [
      {
        path: ':id',
        name: 'product',
        component: () => import('@/views/product'),
        meta: { title: '课程详情' }
      }
    ]
  },

  {
    path: '/info',
    component: BasicLayout,
    children: [
      {
        path: ':id',
        name: 'info',
        component: () => import('@/views/info'),
        meta: { title: '资讯详情' }
      }
    ]
  },

  {
    path: '/cashier',
    component: BasicLayout,
    children: [
      {
        path: ':id',
        name: 'cashier',
        component: () => import('@/views/cashier'),
        meta: { title: '收银台' }
      },
      {
        path: 'result/:id',
        name: 'cashier-result',
        component: () => import('@/views/cashier/result'),
        meta: { title: '支付结果' }
      },
    ]
  },

  {
    path: '/mine',
    component: BasicLayout,
    children: [
      {
        path: 'collection',
        name: 'mine-collection',
        component: () => import('@/views/mine/collection'),
        meta: { title: '我的收藏' }
      },
      {
        path: 'history',
        name: 'mine-history',
        component: () => import('@/views/mine/history'),
        meta: { title: '我的足迹' }
      },
      {
        path: 'coupon',
        name: 'mine-coupon',
        component: () => import('@/views/mine/coupon'),
        meta: { title: '我的优惠券' }
      },
      {
        path: 'order',
        name: 'mine-order',
        component: () => import('@/views/mine/order'),
        meta: { title: '订单管理' }
      },
      {
        path: 'order/detail/:id',
        name: 'mine-order-detail',
        component: () => import('@/views/mine/order/detail'),
        meta: {
          title: '订单详情',
          navbar: {
            style: { backgroundColor: 'rgba(0, 0, 0, 0)', color: '#ffffff' }
          }
        }
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
